package com.lz.commonlibrary.helper;

import android.app.Activity;
import android.content.Context;
import android.support.v4.app.Fragment;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;

/**
 * @author 黄赛赛
 * @version V1.0
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}()
 * @date 2016/5/7 22:11
 */
public class GlideHelper {
    public  static   void loadImage(ImageView imgView, String url,Activity activity, boolean isSmallUrl){
        Glide.with(activity)
                .load(url)
                .centerCrop()
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(imgView);
    }

    public  static   void loadImage(ImageView imgView, String url,Fragment fragment, boolean isSmallUrl){
        Glide.with(fragment)
                .load(url)
                .centerCrop()
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(imgView);
    }

    public  static   void loadImage(ImageView imgView, String url,Context context, boolean isSmallUrl){
        Glide.with(context)
                .load(url)
                .centerCrop()
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(imgView);
    }

    public  static   void loadImage(ImageView imgView, String url, int defaultImgResId,Activity activity, boolean isSmallUrl){
        Glide.with(activity)
                .load(url)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .placeholder(defaultImgResId)
                .centerCrop()
                .into(imgView);
    }

    public  static   void loadImage(ImageView imgView, String url,int defaultImgResId,Fragment fragment, boolean isSmallUrl){
        Glide.with(fragment)
                .load(url)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .centerCrop()
                .placeholder(defaultImgResId)
                .into(imgView);
    }

    public  static   void loadImage(ImageView imgView, String url,int defaultImgResId,Context context, boolean isSmallUrl){
        Glide.with(context)
                .load(url)
                .centerCrop()
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .placeholder(defaultImgResId)
                .into(imgView);
    }



    /*
    *
    * DrawableRequestBuilder requestBuilder = Glide.with(context).load(imageUrl);
        requestBuilder.into(imageView);
    * */

    /*downloadOnly
    *
    *
    FutureTarget<File> future = Glide.with(applicationContext)
    .load(yourUrl)
    .downloadOnly(500, 500);
      File cacheFile = future.get();
    *
    * */

 /*
If you actually want to interact with a decoded image on a background thread, instead of using downloadOnly
  Bitmap myBitmap = Glide.with(applicationContext)
            .load(yourUrl)
            .asBitmap()
            .centerCrop()
            .into(500, 500)
            .get()*/


/**
 *
 *
 *     1.Glide.with(context).resumeRequests()和 Glide.with(context).pauseRequests()
 当列表在滑动的时候，调用pauseRequests()取消请求，滑动停止时，调用resumeRequests()恢复请求。这样是不是会好些呢？


 2.Glide.clear()

 3.ListPreloader
 如果你想让列表预加载的话，不妨试一下ListPreloader这个类。
 */


    /**
     *glide-transformations
     * https://github.com/wasabeef/glide-transformations
     * Crop

     CropTransformation, CropCircleTransformation, CropSquareTransformation, RoundedCornersTransformation

     Color

     ColorFilterTransformation, GrayscaleTransformation

     Blur

     BlurTransformation

     Mask

     MaskTransformation

     GPU Filter (use GPUImage)
      */

/*


    case Mask: {
        int width = Utils.dip2px(mContext, 133.33f);
        int height = Utils.dip2px(mContext, 126.33f);
        Glide.with(mContext)
                .load(R.drawable.check)
                .override(width, height)
                .bitmapTransform(new CenterCrop(mContext),
                        new MaskTransformation(mContext, R.drawable.mask_starfish))
                .into(holder.image);
        break;
    }
    case NinePatchMask: {
        int width = Utils.dip2px(mContext, 150.0f);
        int height = Utils.dip2px(mContext, 100.0f);
        Glide.with(mContext)
                .load(R.drawable.check)
                .override(width, height)
                .bitmapTransform(new CenterCrop(mContext),
                        new MaskTransformation(mContext, R.drawable.mask_chat_right))
                .into(holder.image);
        break;
    }
    case CropTop:
            Glide.with(mContext)
            .load(R.drawable.demo)
    .bitmapTransform(
            new CropTransformation(mContext, 300, 100, CropTransformation.CropType.TOP))
            .into(holder.image);
    break;
    case CropCenter:
            Glide.with(mContext)
            .load(R.drawable.demo)
    .bitmapTransform(new CropTransformation(mContext, 300, 100))
            .into(holder.image);
    break;
    case CropBottom:
            Glide.with(mContext)
            .load(R.drawable.demo)
    .bitmapTransform(
            new CropTransformation(mContext, 300, 100, CropTransformation.CropType.BOTTOM))
            .into(holder.image);

    break;
    case CropSquare:
            Glide.with(mContext)
            .load(R.drawable.demo)
    .bitmapTransform(new CropSquareTransformation(mContext))
            .into(holder.image);
    break;
    case CropCircle:
            Glide.with(mContext)
            .load(R.drawable.demo)
    .bitmapTransform(new CropCircleTransformation(mContext))
            .into(holder.image);
    break;
    case ColorFilter:
            Glide.with(mContext)
            .load(R.drawable.demo)
    .bitmapTransform(new ColorFilterTransformation(mContext, Color.argb(80, 255, 0, 0)))
            .into(holder.image);
    break;
    case Grayscale:
            Glide.with(mContext)
            .load(R.drawable.demo)
    .bitmapTransform(new GrayscaleTransformation(mContext))
            .into(holder.image);
    break;
    case RoundedCorners:
            Glide.with(mContext)
            .load(R.drawable.demo)
    .bitmapTransform(new RoundedCornersTransformation(mContext, 30, 0,
                     RoundedCornersTransformation.CornerType.BOTTOM))
            .into(holder.image);
    break;
    case Blur:
            Glide.with(mContext)
            .load(R.drawable.check)
    .bitmapTransform(new BlurTransformation(mContext, 25))
            .into(holder.image);
    break;
    case Toon:
            Glide.with(mContext)
            .load(R.drawable.demo)
    .bitmapTransform(new ToonFilterTransformation(mContext))
            .into(holder.image);
    break;
    case Sepia:
            Glide.with(mContext)
            .load(R.drawable.check)
    .bitmapTransform(new SepiaFilterTransformation(mContext))
            .into(holder.image);
    break;
    case Contrast:
            Glide.with(mContext)
            .load(R.drawable.check)
    .bitmapTransform(new ContrastFilterTransformation(mContext, 2.0f))
            .into(holder.image);
    break;
    case Invert:
            Glide.with(mContext)
            .load(R.drawable.check)
    .bitmapTransform(new InvertFilterTransformation(mContext))
            .into(holder.image);
    break;
    case Pixel:
            Glide.with(mContext)
            .load(R.drawable.check)
    .bitmapTransform(new PixelationFilterTransformation(mContext, 20))
            .into(holder.image);
    break;
    case Sketch:
            Glide.with(mContext)
            .load(R.drawable.check)
    .bitmapTransform(new SketchFilterTransformation(mContext))
            .into(holder.image);
    break;
    case Swirl:
            Glide.with(mContext)
            .load(R.drawable.check)
    .bitmapTransform(
            new SwirlFilterTransformation(mContext, 0.5f, 1.0f, new PointF(0.5f, 0.5f)))
            .into(holder.image);
    break;
    case Brightness:
            Glide.with(mContext)
            .load(R.drawable.check)
    .bitmapTransform(new BrightnessFilterTransformation(mContext, 0.5f))
            .into(holder.image);
    break;
    case Kuawahara:
            Glide.with(mContext)
            .load(R.drawable.check)
    .bitmapTransform(new KuwaharaFilterTransformation(mContext, 25))
            .into(holder.image);
    break;
    case Vignette:
            Glide.with(mContext)
            .load(R.drawable.check)
    .bitmapTransform(new VignetteFilterTransformation(mContext, new PointF(0.5f, 0.5f),
    new float[] { 0.0f, 0.0f, 0.0f }, 0f, 0.75f))
            .into(holder.image);
    break;

     */


    /*
      Glide.with(this).load(URL)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .centerCrop()
                .listener(GlidePalette.with(URL)
                        .use(GlidePalette.Profile.VIBRANT)
                        .intoBackground(textVibrant, GlidePalette.Swatch.RGB)
                        .intoTextColor(textVibrant, GlidePalette.Swatch.BODY_TEXT_COLOR)
                        .crossfade(true)
                        .use(GlidePalette.Profile.VIBRANT_DARK)
                        .intoBackground(textVibrantDark, GlidePalette.Swatch.RGB)
                        .intoTextColor(textVibrantDark, GlidePalette.Swatch.BODY_TEXT_COLOR)
                        .crossfade(false)
                        .use(GlidePalette.Profile.VIBRANT_LIGHT)
                        .intoBackground(textVibrantLight, GlidePalette.Swatch.RGB)
                        .intoTextColor(textVibrantLight, GlidePalette.Swatch.BODY_TEXT_COLOR)
                        .crossfade(true, 1000)

                        .use(GlidePalette.Profile.MUTED)
                        .intoBackground(textMuted, GlidePalette.Swatch.RGB)
                        .intoTextColor(textMuted, GlidePalette.Swatch.BODY_TEXT_COLOR)
                        .use(GlidePalette.Profile.MUTED_DARK)
                        .intoBackground(textMutedDark, GlidePalette.Swatch.RGB)
                        .intoTextColor(textMutedDark, GlidePalette.Swatch.BODY_TEXT_COLOR)
                        .crossfade(true, 2000)
                        .use(GlidePalette.Profile.MUTED_LIGHT)
                        .intoBackground(textMutedLight, GlidePalette.Swatch.RGB)
                        .intoTextColor(textMutedLight, GlidePalette.Swatch.BODY_TEXT_COLOR)

                        // optional
                        .intoCallBack(new BitmapPalette.CallBack() {
                            @Override
                            public void onPaletteLoaded(@Nullable Palette palette) {
                                //specific task
                            }
                        })

                        // optional
                        .setGlideListener(new RequestListener<String, GlideDrawable>() {
                            @Override
                            public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                                return false;
                            }

                            @Override
                            public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                                return false;
                            }
                        })

                        // optional: do stuff with the builder
                        .setPaletteBuilderInterceptor(new BitmapPalette.PaletteBuilderInterceptor() {
                            @NonNull
                            @Override
                            public Palette.Builder intercept(Palette.Builder builder) {
                                return builder.resizeBitmapSize(100);
                            }
                        })
                )
                .into(imageView);
    */
}

